package com.chisheng.write;

import com.alibaba.excel.EasyExcel;
import com.chisheng.pojo.Student;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * EasyExcel 写测试
 *
 * @author chisheng
 * @since 2021-10-28
 */
public class EasyExcelWriteDemo {

    @Test
    public void test() {
        String excel = "F:\\project\\codelabs\\easy-excel-demo\\src\\main\\resources\\student.xlsx";

        /* pathName: 文件路径
         * head: 实体类 class */
        EasyExcel.write(excel, Student.class)
                .sheet("学生表")  /* 设置 sheet 表名称 */
                .doWrite(studentList());  /* 数据写入 */
    }

    private static List<Student> studentList() {
        ArrayList<Student> studentList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            studentList.add(new Student(
                    UUID.randomUUID().toString().replace("-", "").substring(5),
                    UUID.randomUUID().toString().replace("-", "").substring(12)
            ));
        }

        return studentList;
    }

}
